import { selSmsReplyAll } from '@/services/smsReply';
import { errNotification, successNotification } from '@/utils/notification';

export default {
    namespace: 'smsReply',
  
    state: {
        smsReplyList: [],
        smsReplyListPage: 1,
        smsReplyListTotal: 0
    },
  
    effects: {
      *fetchSelSmsReplyAll(param, { call, put }) { //查询平台接收短信
        const response = yield call(selSmsReplyAll, param);
        if(response.success){
            yield put({
                type: 'setSmsReplyList',
                payload: response.data,
            });
        }
      },
    },
  
    reducers: {
      setSmsReplyList(state, action) {
        if(action.payload.list){
          action.payload.list.map((item,index)=>{
           item.key = item.id
           if(item.children){
            item.children.map((item,index)=>{
              item.key = item.id
            })
           }
          })
        }
        return {
            ...state,
            smsReplyList: action.payload.list,
            smsReplyListPage: action.payload.pageNum,
            smsReplyListTotal: action.payload.total
        };
      },
    },
  };